﻿using System;
using System.Text.Json.Serialization;

namespace CleanArchitecture.Core.Configuration
{
    public partial class  NowaConfig
    {
        private int _qiniuExpire;
        private bool _rownumberSupportForSqlserver2008 = false;
        /// <summary>
        /// Gets or sets a value indicating whether to display the full error in production environment.
        /// It's ignored (always enabled) in development environment
        /// </summary>
        public bool DisplayFullErrorStack { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether we should use Redis server for caching (instead of default in-memory caching)
        /// </summary>
        public bool RedisCachingEnabled { get; set; }
        /// <summary>
        /// Gets or sets Redis connection string. Used when Redis caching is enabled
        /// </summary>
        public string RedisCachingConnectionString { get; set; }
        /// <summary>
        /// Gets or sets a value indicating whether the data protection system should be configured to persist keys in the Redis database
        /// </summary>
        public bool PersistDataProtectionKeysToRedis { get; set; }

        /// <summary>
        /// Gets or sets path to database with user agent strings
        /// </summary>
        public string UserAgentStringsPath { get; set; }
        /// <summary>
        /// Gets or sets path to database with crawler only user agent strings
        /// </summary>
        public string CrawlerOnlyUserAgentStringsPath { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether we should ignore startup tasks
        /// </summary>
        public bool IgnoreStartupTasks { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether to load an assembly into the load-from context, bypassing some security checks.
        /// </summary>
        public bool UseUnsafeLoadAssembly { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether to use backwards compatibility with SQL Server 2008 and SQL Server 2008R2
        /// DavidLee 2019/12/20 关闭此功能支持，EFCore3.1以后已停止对Sql Server2008对
        /// 分页查询使用RowNumber, 有关信息可参考https://www.cnblogs.com/jhli/p/9962372.html
        /// </summary>
        [Obsolete("Row-number paging is no longer supported. See https://ak.ms/AA6h122 for more information.")]
        public bool UseRowNumberForPaging //{ get; set; }
        {
            get 
            {
                if (_rownumberSupportForSqlserver2008)
                    throw new NowaException("Row Number For Paging is no longer supporting!");
                return _rownumberSupportForSqlserver2008 ; 
            }
            set { _rownumberSupportForSqlserver2008 = value;}
        }

        /// <summary>
        /// Gets or sets a value indicating whether to store TempData in the session state.
        /// By default the cookie-based TempData provider is used to store TempData in cookies.
        /// </summary>
        public bool UseSessionStateTempDataProvider { get; set; }

        public string BaiduAddressAccessKey { get; set; }

        public string BaiduAddressSecretKey { get; set; }
        public string BaiduFanyiAPPID { get; set; }
        public string BaiduFanyiSecretKey { get; set; }
        /// <summary>
        /// Qiniu Cloud API AccessKey
        /// </summary>
        public string QiniuAccessKey { get; set; }
        /// <summary>
        /// Qiniu Cloud API SecretKey
        /// </summary>
        public string QiniuSecretKey { get; set; }
        /// <summary>
        /// Qiniu Cloud API Bucket name for where to upload files to store
        /// </summary>
        public string QiniuBucketName { get; set; }
        /// <summary>
        /// Qiniu Cloud Domain for files access
        /// </summary>
        public string QiniuDomain { get; set; }

        public int QiniuUploadExpire 
        { 
            get => _qiniuExpire; 
            set { _qiniuExpire = value <= 0 ? 3600 : value; }
        }

        public string QiniuUploadZone { get; set; }
        /// <summary>
        /// Gets a value indicating whether we should use Qiniu Cloud storage
        /// </summary>
        [JsonIgnore]
        public bool QiniuCloudStorageEnabled => !(string.IsNullOrEmpty(QiniuAccessKey) && string.IsNullOrEmpty(QiniuSecretKey));
    }
}
